package com.im.gateway.tcp;

import com.im.common.ImConstant;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @Created leijun
 * @Date 2021/11/7 10:55 下午
 */
@Component
public class ChildHandler extends ChannelInitializer<SocketChannel> {

    @Resource
    private GatewayTcpHandler gatewayTcpHandler;

    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ByteBuf delimiter = Unpooled.copiedBuffer(ImConstant.DELIMITER);
        socketChannel.pipeline().addLast(new DelimiterBasedFrameDecoder(4096, delimiter));
        socketChannel.pipeline().addLast(gatewayTcpHandler);
    }
}
